import Mock from 'mockjs'

const Random=Mock.Random;

// Mock.mock('/api/user','get',{
//     code:200,
//     message:"操作成功",
//     data:{
//         id:1,
//         name:Random.cname(),            //生成随机中文名
//         gender:Random.pick(["男","女"]),//生成随机性别
//         birthday:Random.date(),         //生成随机日期
//         email:Random.email(),           //生成随机邮箱
//         bio:Random.csentence(10,20),    //生成随机个人简介
//     }
// });

const users=Mock.mock({
    'list|1-10':[{
        'id|+1':1,
        name:() => Random.cname(),            
        gender:() => Random.pick(["男","女"]),
        birthday:() => Random.date(),         
        email:() => Random.email(),           
        bio:() => Random.csentence(10,20),
    }]
});

Mock.mock('/api/user/getList','get',{
    code:200,
    message:"操作成功",
    data:users.list,
});


Mock.mock(/\/api\/user\/getUserById/,'get',(req,res) => {
    const id=req.url.match(/id=(\d+)/)[1];
    const user=users.list.find((user) => (user.id == id))

    return {
        code:200,
        message:"操作成功",
        data:user,
    };
});

